package com.wiscamp.ninechapters.problems.math;

import com.wiscamp.ninechapters.common.core.ParseHelper;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.math.BigDecimal;

/**
 * 有限小数
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class LatexDecimal extends LatexNumber {
    private BigDecimal value;

    public String getLatex() {
        return String.valueOf(value.stripTrailingZeros());
    }


    public String getLatex(int scale) {
        var scaleDecimal = value.setScale(scale);
        return String.valueOf(scaleDecimal.stripTrailingZeros());
    }

    public LatexDecimal(BigDecimal value) {
        this.value = value;
    }

    public LatexDecimal(String valueText) {
        this.value = ParseHelper.parseBigDecimal(valueText);
    }
}
